<template>
  <el-dialog
    title="选择工艺路线"
    :visible="selectProcessDialog"
    width="70%"
    class="Process-select"
    @close="selectProcessClose"
  >
    <div class="app-container Process-box">
      <el-row :gutter="20">
        <el-col :span="24" :xs="24">
          <el-form
            :inline="true"
            class="ma-search"
            label-width="68px"
            style="margin-bottom: 8px;display:flex;justify-content: flex-end;"
          >
            <div class="ma-right">
              <el-button
                type="primary"
                plain
                icon="el-icon-menu"
                size="mini"
                @click="handleAllSuccess"
                >全选
              </el-button>
              <el-button
                type="primary"
                plain
                icon="el-icon-collection-tag"
                :class="{ 'is-plan': continuityStatus }"
                size="mini"
                @click="handleContinuity"
                >连选
              </el-button>
            </div>
          </el-form>
          <!-- 工艺路线数据 -->
          <el-table
            :data="operateData"
            border
            v-loading="loading"
            :height="maxHeight"
            @row-dblclick="handleProcessSelect"
          >
            <el-table-column
              type="index"
              width="60"
              align="center"
              label="序号"
            >
            </el-table-column>
            <el-table-column label="工序代码" align="center" prop="code">
            </el-table-column>
            <el-table-column label="工序名称" align="center" prop="name">
            </el-table-column>
            <el-table-column
              label="标准工时"
              prop="workTypeCn"
              width="140"
              align="center"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.duration }}&nbsp;分钟</span>
              </template>
            </el-table-column>
            <el-table-column label="是否质检" width="140" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.isQuality == '1'">是</span>
                <span v-else>否</span>
              </template>
            </el-table-column>
            <el-table-column label="计件方式" width="140" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.countType == '0'">班组</span>
                <span v-else>个人</span>
              </template>
            </el-table-column>
            <el-table-column
              label="排序"
              prop="orderId"
              width="100"
              align="center"
            />

            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding"
              width="80"
            >
              <template slot-scope="scope">
                <div class="public-btn">
                  <el-button
                    size="mini"
                    type="text"
                    @click.stop="handleProcessSelect(scope.row)"
                    >选择
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页信息 -->
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getProcesslList"
          />
        </el-col>
      </el-row>
    </div>
  </el-dialog>
</template>
<script>
import { seeProcess } from "../../api/product";
let self;
export default {
  name: "Process",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        code: "",
        name: "",
      },
      // 总条数
      total: 0,
      // 最大高度
      maxHeight: null,
      number: 0,
      //工艺路线数据
      operateData: [],
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
      //连选状态
      continuityStatus: false,
      //弹框提交按钮状态，1（新增） 2（修改）
      butChange: "",
    };
  },
  props: {
    selectProcessDialog: {
      type: Boolean,
      default: true,
    },
    detailCode: {
      type: String,
      value: "",
    },
  },
  beforeCreate() {
    self = this;
  },
  created() {
    this.getProcesslList();
  },
  methods: {
    // 获取工艺路线
    getProcesslList() {
      this.loading = true;
      seeProcess({ processCode: this.detailCode }).then((res) => {
        if (res.code == 200) {
          this.loading = false;
          if (res.data !== undefined && res.data.prsProcessSectionList) {
            this.operateData = res.data.prsProcessSectionList;
          }

          this.maxHeight = `${document.documentElement.clientHeight}` - 380;
        }
      });
    },

    //连选
    handleContinuity() {
      this.continuityStatus = !this.continuityStatus;
      if (this.continuityStatus == false) {
        this.operateData.forEach((value) => {
          value.background = false;
        });
      }
    },
    
  //全选
    handleAllSuccess(){
       this.$emit(
        "handleAllSuccess",
        this.operateData
      );
    },
    // 弹框状态
    selectProcessClose() {
      this.$emit("selectProcessClose");
    },

    // 选择工艺路线
    handleProcessSelect(row) {
      if (this.continuityStatus == true) {
        row.background = true;
      }
      this.number++;
      this.$emit(
        "handleProcessSelect",
        row,
        this.continuityStatus,
        this.number
      );
    },

    //搜索
    search() {
      this.getProcesslList();
    },

    // 查询所有
    checkleAll() {
      //清空搜索信息，避免干扰
      this.queryParams.code = "";
      this.queryParams.name = "";

      this.getProcesslList();
    },

    /** 弹框取消 */
    cancel() {
      this.open = false;
      this.reset();
    },
    close() {
      this.number = 0;
      this.reset();
    },
  },
};
</script>
<style lang="scss">
.Process-select {
  .ma-search {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .is-plan {
    background: #67c23a !important;
    border-color: #67c23a !important;
    color: #ffffff !important;
    outline: none !important;
  }

  .ma-right {
    .el-form-item {
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }

    label {
      width: auto;
      flex-grow: 1;
    }

    .el-form-item__content {
      margin-left: 0px !important;
      margin-right: 0 !important;
    }
  }

  .el-dialog__body {
    height: calc(100vh - 250px);
  }
  .el-range-editor--medium.el-input__inner {
    line-height: 32px;
  }
  .el-range-editor--medium .el-range__icon,
  .el-range-editor--medium .el-range__close-icon,
  .el-range-editor--medium .el-range-separator {
    line-height: 24px;
  }
  .el-range-editor--medium.el-input__inner {
    height: 32px;
  }
  .custom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .app-container {
    padding-top: 0;
  }

  .el-table {
    cursor: pointer;
  }

  .el-table__body {
    user-select: none;
  }

  .Process-box {
    .el-tag.el-tag--info {
      color: #1890ff;
    }
    .el-switch {
      display: flex;
      justify-content: center;
    }
    .el-dialog__body {
      padding-right: 15px;
      padding-bottom: 20px;
    }

    .el-input.is-disabled .el-input__inner {
      color: #333;
    }

    .el-form-item--medium .el-form-item__content {
      margin-right: 10px !important;
    }
  }
}
</style>
